package sys

import (
	"context"
	"github.com/google/wire"
	"sieve_admin_server/app/api/util"
	"sieve_admin_server/app/contextx"
	"sieve_admin_server/app/schema"
	"sieve_admin_server/app/server"
	serviceSys "sieve_admin_server/app/service/sys"
)

var (
	_         util.API = (*NoticeAPI)(nil)
	NoticeSet          = wire.NewSet(wire.Struct(new(NoticeAPI), "*"))
)

type NoticeAPI struct {
	util.EmptyAPI
	NoticeSrv *serviceSys.NoticeSrv
	MenuSrv   *serviceSys.MenuSrv
}

func (a *NoticeAPI) GetApis() []*server.BatchModTree {
	return []*server.BatchModTree{
		{
			Obj:   a,
			Name:  "notice",
			Title: "提示管理", Perms: []*server.Perm{
				{Name: "add", Title: "新增"},
				{Name: "query", Title: "查询"},
				{Name: "edit", Title: "修改"},
				{Name: "del", Title: "删除"},
				{Name: "enable", Title: "启用"},
				{Name: "disable", Title: "禁用"},
			},
			Order: 7,
		},
	}
}

func (a *NoticeAPI) API_add_item(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("menu_name"),
				contextx.NewVar("title"),
				contextx.NewVar("content"),
			},
		)
	)

	return a.NoticeSrv.Create(context.Background(), reqArgs)
}

func (a *NoticeAPI) API_query_list(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("menu_name"),
				contextx.NewVar("start", true),
				contextx.NewVar("end", true),
			},
		)

		p = schema.PaginationParam{
			PageIndex: util.ToInt(ctx.Args.Get("page_index")),
			PageSize:  util.ToInt(ctx.Args.Get("page_size")),
		}
	)

	return a.NoticeSrv.Query(context.Background(), reqArgs, p)
}

func (a *NoticeAPI) API_edit_item(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("id", true),
				contextx.NewVar("menu_name"),
				contextx.NewVar("title"),
				contextx.NewVar("content"),
			},
		)
	)

	return a.NoticeSrv.Update(context.Background(), reqArgs)
}

func (a *NoticeAPI) API_enable_item(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("id", true),
			},
		)
	)

	return a.NoticeSrv.Enable(context.Background(), reqArgs)
}

func (a *NoticeAPI) API_disable_item(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("id", true),
			},
		)
	)

	return a.NoticeSrv.Disable(context.Background(), reqArgs)
}

func (a *NoticeAPI) API_del_item(ctx *server.Context) interface{} {

	var (
		reqArgs = contextx.GetRequestArgs(ctx,
			[]contextx.Var{
				contextx.NewVar("id", true),
			},
		)
	)

	return a.NoticeSrv.Delete(context.Background(), reqArgs)
}
